package com.fgcs.member.service.serviceImpl;

import com.fgcs.exception.ServiceException;
import com.fgcs.member.dao.WholeDao;
import com.fgcs.member.pojo.Whole;
import com.fgcs.member.service.WholeService;
import com.fgcs.pojo.PageObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class WholeImpl  implements WholeService {
    @Autowired
    private WholeDao wholeDao;
    @Override
    public PageObject<Whole> findPageObjects(String name, Integer pageCurrent) {
        if(pageCurrent==null || pageCurrent<1)
            throw new IllegalArgumentException("页码值不合法");
        int rowCount = wholeDao.getRowCount(name);
        if(rowCount==0)
            throw new ServiceException("没有找到对应的记录");
        int pageSize=5;
        int startIndex=(pageCurrent-1)*pageSize;
        List<Whole> records =
        wholeDao.findPageObjects(name, startIndex,pageSize );
//        PageObject<Whole> PageObject = new PageObject<>();
//        PageObject.setRowCount(rowCount);
//        PageObject.setRecords(records);
//        PageObject.setPageSize(pageSize);
//        PageObject.setPageCount(pageCurrent);
//        int pageCount = rowCount/pageSize;
//        if(rowCount%pageSize!=0)pageCount++;
//        PageObject.setRowCount(pageCount);
        return new PageObject<>(rowCount, records, pageSize, pageCurrent);
    }
}
